package henu.graduation_design.adapter;

import henu.graduation_design.onlineshop.R;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AppraiseAdapter extends BaseAdapter {

	private Context context;
	private List<HashMap<String, Object>> list;

	public AppraiseAdapter(Context context, List<HashMap<String, Object>> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final AppraiseHolder holder;
		if (convertView == null) {
			View view = LayoutInflater.from(context).inflate(
					R.layout.listview_appraise_cell, null);
			holder = new AppraiseHolder();
			holder.nameTextView = (TextView) view
					.findViewById(R.id.nameTextView);
			holder.timeTextView = (TextView) view
					.findViewById(R.id.timeTextView);
			holder.contentTextView = (TextView) view
					.findViewById(R.id.commentTextView);
			view.setTag(holder);
			convertView = view;
		} else {
			holder = (AppraiseHolder) convertView.getTag();
		}
		final HashMap<String, Object> currentItem = list.get(position);

		holder.nameTextView.setText(currentItem.get("name").toString());
		holder.timeTextView.setText(currentItem.get("time").toString());
		holder.contentTextView.setText(currentItem.get("comment").toString());
		return convertView;
	}

	private class AppraiseHolder {
		private TextView nameTextView;
		private TextView timeTextView;
		private TextView contentTextView;
	}

}
